package com.artifact.mit.mypoint.activity;

import static com.artifact.mit.mypoint.util.Variable.PREFS_NAME;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.artifact.mit.mypoint.R;
import com.artifact.mit.mypoint.async.MenuAsyncTask;
import com.artifact.mit.mypoint.async.PointAsync;
import com.artifact.mit.mypoint.async.PromoLoader;
import com.artifact.mit.mypoint.util.APICall.ImageLoader;
import com.artifact.mit.mypoint.util.SetImage;

public class DashboardActivity extends Fragment {

	private TextView name;
	private TextView memberUserId;
	private TextView point;
	private TextView promoName1;
	private TextView promoName2;
	private TextView promoDesc1;
	private TextView promoDesc2;
	private ImageView promoImage1;
	private ImageView promoImage2;
	private ImageView profile;
	private Button btnPromo;
	
	private SharedPreferences preferences;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		return inflater.inflate(R.layout.dashboard_layout, null);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		name = (TextView) getView().findViewById(R.id.name);
		memberUserId = (TextView) getView().findViewById(R.id.id);
		point = (TextView) getView().findViewById(R.id.point);
		profile = (ImageView) getView().findViewById(R.id.profile);
		preferences = getActivity().getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);

		promoName1 = (TextView) getView().findViewById(R.id.promoText1);
		promoDesc1 = (TextView) getView().findViewById(R.id.promoText2);
		promoImage1 = (ImageView) getView().findViewById(R.id.promoImage1);
		
		promoName2 = (TextView) getView().findViewById(R.id.promoText3);
		promoDesc2 = (TextView) getView().findViewById(R.id.promoText4);
		promoImage2 = (ImageView) getView().findViewById(R.id.promoImage2);
		
		btnPromo = (Button) getView().findViewById(R.id.btnPromo);

		MenuAsyncTask menuAsyncTask = new MenuAsyncTask(getActivity());
		menuAsyncTask.execute("");

		PointAsync pointAsync = new PointAsync(getActivity(), point);
		pointAsync.execute("");

		PromoLoader promoLoader = new PromoLoader(getActivity(), promoName1, promoDesc1, promoImage1, promoName2, promoDesc2, promoImage2);
		promoLoader.execute("");

		name.setText(preferences.getString("name", ""));
		memberUserId.setText(preferences.getString("memberUserId", ""));
		point.setText(preferences.getString("point", ""));

		new ImageLoader().execute(new SetImage(profile, preferences.getString("image", ""), false));
	}
}